package com.thtn.greendroidthtneg2;

import greendroid.app.GDListActivity;
import greendroid.widget.ActionBar;
import greendroid.widget.ActionBarItem;
import greendroid.widget.ItemAdapter;
import greendroid.widget.QuickAction;
import greendroid.widget.QuickActionBar;
import greendroid.widget.QuickActionWidget;
import greendroid.widget.item.Item;
import greendroid.widget.item.TextItem;
import greendroid.widget.itemview.ItemView;

import java.util.ArrayList;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.ColorFilter;
import android.graphics.LightingColorFilter;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.Toast;

public class SearchableDictionary extends GDListActivity {
	public static boolean COPYING_DATABASE = false;
	public static String TAG = "SearchableDictionary";
	final byte AUDIO = 4;
	final byte AUDIO_DOWNLOAD = 3;
	final byte AUDIO_SAVE = 4;
	final byte BOOKMARK = 0;
	final byte DATA_COPY = 5;
	final byte INFO = 3;
	final byte RANDOM = 1;
	final byte SEARCH = 2;
	private QuickActionWidget.OnQuickActionClickListener mActionListener = new QuickActionWidget.OnQuickActionClickListener() {
		public void onQuickActionClicked(
				QuickActionWidget paramAnonymousQuickActionWidget,
				int paramAnonymousInt) {
			switch (paramAnonymousInt) {

			case BOOKMARK:
				// Intent localIntent3 = new Intent(
				// SearchableDictionary.this.getBaseContext(),
				// BookmarksActivity.class);
				// SearchableDictionary.this.startActivity(localIntent3);
				Toast.makeText(SearchableDictionary.this,
						"Item " + BOOKMARK + " clicked", Toast.LENGTH_SHORT)
						.show();

				return;
			case SEARCH:
				// SearchableDictionary.this.onSearchRequested();
				// SearchableDictionary.this.showDialog(3);
				Toast.makeText(SearchableDictionary.this,
						"Item " + SEARCH + " clicked", Toast.LENGTH_SHORT)
						.show();

				return;
			case INFO:
				// Intent localIntent2 = new Intent(
				// SearchableDictionary.this.getBaseContext(), Info.class);
				// localIntent2.putExtra("info",
				// SearchableDictionary.this.getText(R.string.about));
				// SearchableDictionary.this.startActivity(localIntent2);
				Toast.makeText(SearchableDictionary.this,
						"Item " + INFO + " clicked", Toast.LENGTH_SHORT).show();

				return;
			case RANDOM:
				// Intent localIntent1 = new Intent(
				// SearchableDictionary.this.getBaseContext(),
				// RandomWordActivity.class);
				// SearchableDictionary.this.startActivity(localIntent1);
				Toast.makeText(SearchableDictionary.this,
						"Item " + RANDOM + " clicked", Toast.LENGTH_SHORT)
						.show();

				return;

			default:
				return;
			}
		}
	};

	QuickActionBar mBar;
	private ListView mListView;
	ProgressDialog mProgressDialog;
	SharedPreferences settings;

	private void prepareQuickActionBar() {
		this.mBar = new QuickActionBar(this);
		// mBar.addQuickAction(new MyQuickAction(this,
		// R.drawable.gd_action_bar_compose, R.string.gd_compose));
		this.mBar.addQuickAction(new MyQuickAction(this,
				R.drawable.gd_action_bar_star, R.string.favorite));

		Log.d(TAG, "favorite =" + getString(R.string.favorite));
		this.mBar.addQuickAction(new MyQuickAction(this,
				R.drawable.gd_action_bar_eye, R.string.random));
		Log.d(TAG, "favorite =" + getString(R.string.random));
		this.mBar.addQuickAction(new MyQuickAction(this,
				R.drawable.gd_action_bar_search, R.string.gd_search));
		this.mBar.addQuickAction(new MyQuickAction(this,
				R.drawable.gd_action_bar_info, R.string.gd_info));
		// this.settings.getString("audio", null);
		this.mBar.setOnQuickActionClickListener(this.mActionListener);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getActionBar().setType(ActionBar.Type.Empty);
		setTitle(R.string.title_name);
		addActionBarItem(ActionBarItem.Type.Settings);
		ArrayList<Item> localArrayList = new ArrayList<Item>();
		localArrayList.add(new CustomTextItem("#"));
		localArrayList.add(new CustomTextItem("A"));
		localArrayList.add(new CustomTextItem("B"));
		localArrayList.add(new CustomTextItem("C"));
		localArrayList.add(new CustomTextItem("D"));
		localArrayList.add(new CustomTextItem("E"));
		localArrayList.add(new CustomTextItem("F"));
		localArrayList.add(new CustomTextItem("G"));
		localArrayList.add(new CustomTextItem("H"));
		localArrayList.add(new CustomTextItem("I"));
		localArrayList.add(new CustomTextItem("J"));
		localArrayList.add(new CustomTextItem("K"));
		localArrayList.add(new CustomTextItem("L"));
		localArrayList.add(new CustomTextItem("M"));
		localArrayList.add(new CustomTextItem("N"));
		localArrayList.add(new CustomTextItem("O"));
		localArrayList.add(new CustomTextItem("P"));
		localArrayList.add(new CustomTextItem("Q"));
		localArrayList.add(new CustomTextItem("R"));
		localArrayList.add(new CustomTextItem("S"));
		localArrayList.add(new CustomTextItem("T"));
		localArrayList.add(new CustomTextItem("U"));
		localArrayList.add(new CustomTextItem("V"));
		localArrayList.add(new CustomTextItem("W"));
		localArrayList.add(new CustomTextItem("X"));
		localArrayList.add(new CustomTextItem("Y"));
		localArrayList.add(new CustomTextItem("Z"));

		setListAdapter(new ItemAdapter(this, localArrayList));
		prepareQuickActionBar();

	}

	public boolean onHandleActionBarItemClick(ActionBarItem paramActionBarItem,
			int paramInt) {
		switch (paramInt) {

		case 0:
			this.mBar.show(paramActionBarItem.getItemView());
			break;
		default:
			return super.onHandleActionBarItemClick(paramActionBarItem,
					paramInt);

		}
		return true;
	}

	class CustomTextItem extends TextItem {
		public CustomTextItem(String arg2) {
			super(arg2);
		}

		public ItemView newView(Context paramContext, ViewGroup paramViewGroup) {
			return createCellFromXml(paramContext, R.layout.result,
					paramViewGroup);
		}
	}

	private static class MyQuickAction extends QuickAction {
		private static final ColorFilter BLACK_CF = new LightingColorFilter(
				-16777216, -16777216);

		public MyQuickAction(Context paramContext, int paramInt1, int paramInt2) {
			super(paramContext, buildDrawable(paramContext, paramInt1),
					paramInt2);
		}

		private static Drawable buildDrawable(Context paramContext, int paramInt) {
			Drawable localDrawable = paramContext.getResources().getDrawable(
					paramInt);
			localDrawable.setColorFilter(BLACK_CF);
			return localDrawable;
		}
	}

	protected void onListItemClick(ListView paramListView, View paramView,
			int paramInt, long paramLong) {
		TextItem localTextItem = (TextItem) paramListView
				.getItemAtPosition(paramInt);
		Intent localIntent = new Intent(getBaseContext(),
				WordListActivity.class);
		localIntent.putExtra("Selection", localTextItem.text);
		startActivity(localIntent);
		Toast.makeText(SearchableDictionary.this,
				"ListItem " + localTextItem.text + " clicked!",
				Toast.LENGTH_SHORT).show();
	}

}
